﻿-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date, ,>
-- Description:	<Description, ,>
-- =============================================
CREATE FUNCTION [dbo].[GetTitlu](@art varchar(40))
RETURNS varchar(10)
AS
BEGIN
	-- Declare the return variable here
	DECLARE @ret varchar(40)
	DECLARE @val int
	DECLARE @pozPct int
	SET @pozPct = CHARINDEX('.', @Art)
	SET @ret = @art
	IF @pozPct>=1
		SET @ret = SUBSTRING(@art,1,@pozPct-1)
	SET @val = CAST(@ret AS int)
	SET @ret = CASE 
		WHEN (@val < 20) THEN 'I'
		WHEN (@val >= 20 AND @val < 30) THEN 'II'
        WHEN (@val >= 30 AND @val < 40)
            THEN 'III'
        WHEN (@val >= 40 AND @val < 50)
            THEN 'IV'
        WHEN (@val >= 50 AND @val < 51)
            THEN 'V'
        WHEN (@val >= 51 AND @val < 55)
            THEN 'VI'
        WHEN (@val >= 55 AND @val < 57)
            THEN 'VII'
        WHEN (@val >= 57 AND @val < 59)
            THEN 'VIII'
        WHEN (@val >= 59 AND @val < 71)
            THEN 'IX'
        WHEN (@val >= 71 AND @val < 72)
            THEN  'X'
        WHEN (@val >= 71 AND @val < 72)
            THEN 'X'
        WHEN (@val >= 72 AND @val < 80)
            THEN 'XI'
        WHEN (@val >= 80 AND @val < 81)
            THEN 'XII'
        WHEN (@val >= 81 AND @val < 90)
            THEN  'XIII'
        WHEN (@val >= 90)  THEN 'XIV'
		ELSE ''        
	end
	RETURN @ret

END